package com.d5xx.hunters.commands;

import com.d5xx.hunters.API.Hunter;
import com.d5xx.hunters.Functions;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabExecutor;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


@SuppressWarnings("NullableProblems")
public class HunterPlayer implements TabExecutor {
    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String a, String[] args) {
        if (!(sender instanceof Player player)) return true;
        com.d5xx.hunters.API.HunterPlayer hunterPlayer = Hunter.getHunterPlayer(player);
        if (args.length == 0) { //子命令长度为0
            //帮助
        } else if (args.length == 1) {
            switch (args[0]) {
                case "help":
                    //发送信息
                    break;
                case "lobby":
                    break;
                case "start":
                    if (hunterPlayer.getType().equals("lobby")) {
                        hunterPlayer.setType("lobby-waiting");
                        Functions.sendWaitingActionaBar(hunterPlayer);
                    } else {
                        hunterPlayer.sendKeyMessage("HunterPlayer-waiting-error", true);
                    }
                    break;
                default:
            }
        }
        return true;
    }
    @Override
    public List<String> onTabComplete(CommandSender sender, Command cmd, String a, String[] args) {
        //Tab补全
        if (args.length == 1) {
            List<String> result = new ArrayList<>(Arrays.asList("help", "lobby", "start"));
            result.removeIf(s -> !s.startsWith(args[0].toLowerCase()));
            return result;
        }
        return null;
    }
}
